package com.tjian.fafa.user.module.home;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.tjian.fafa.user.R;
import com.tjian.fafa.user.base.ConnectedApp;
import com.tjian.fafa.user.base.bean.TabMsgItemEntity;
import com.tjian.fafa.user.base.bean.UserInfo;
import com.tjian.fafa.user.base.frame.SimpleBackPage_fafa;
import com.tjian.fafa.user.base.frame.UIHelper_fafa;
import com.tjian.fafa.user.base.mainBody.MainBodyActivity;

import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.List;

public class MainTabMyPageExtendActivity extends Activity
{

    private static MainTabMyPageExtendActivity mInstance;

    private List<Integer> mListOfIds;
    private List<TabMsgItemEntity> mListOfEntity;

    private int mNotifId = 1;

    private LinearLayout myDataRelativeLayout_os;
    private LinearLayout fafa_instant_delivery_activity_linearlayout;
    private LinearLayout develop_test_page_home_fragment_linearlayout;
    private LinearLayout baidumapzoomiconchangeactivity_linearlayout;
    private LinearLayout mapcontroldemo_fafa_linearlayout;


    private TextView login_nameTextView;
    private TextView curLocationTextView;
    private ImageView avatarImage;

    public static MainTabMyPageExtendActivity getInstance()
    {
        if (mInstance == null)
        {
            mInstance = new MainTabMyPageExtendActivity();
        }
        return mInstance;
    }

    public List<TabMsgItemEntity> getListOfEntity()
    {
        return mListOfEntity;
    }

    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        this.requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.tabmy_main_extend_function);


        mInstance = this;
        //os
        myDataRelativeLayout_os = (LinearLayout) findViewById(R.id.main_tab_my_os);
        fafa_instant_delivery_activity_linearlayout = (LinearLayout) findViewById(R.id.fafa_instant_delivery_activity_linearlayout_id);
        develop_test_page_home_fragment_linearlayout = (LinearLayout) findViewById(R.id.develop_test_page_home_fragment_linearlayout_id);
        baidumapzoomiconchangeactivity_linearlayout = (LinearLayout) findViewById(R.id.baidumapzoomiconchangeactivity_linearlayout_id);
        mapcontroldemo_fafa_linearlayout = (LinearLayout) findViewById(R.id.mapcontroldemo_fafa_linearlayout_id);


        login_nameTextView = (TextView) findViewById(R.id.login_name);
        curLocationTextView = (TextView) findViewById(R.id.tabmsg_item_text_latest_msg);

        avatarImage = (ImageView) findViewById(R.id.avatar_id);

        UserInfo me = ConnectedApp.getInstance().getUserInfo();
        //验证是否登录。
        if (me == null)
        {
        }
        else
        {
            /*String loginName = me.getName();
            String curLocation = me.getCurLocation();
            login_nameTextView.setText(loginName);
            curLocationTextView.setText(curLocation);
            String urlString = ConfigOfFafa.projectWebsiteUrl + me.getmAvatarImagePath();
            Bitmap map = ImageUtil.getBitMapForStringURL(urlString);
            avatarImage.setImageBitmap(map);*/
        }

        myDataRelativeLayout_os.setOnClickListener(new View.OnClickListener()
        {
            @Override
            public void onClick(View v)
            {
                MainBodyActivity.getInstance().gotoOsMainActivity_os();
            }
        });

        fafa_instant_delivery_activity_linearlayout.setOnClickListener(new View.OnClickListener()
        {
            @Override
            public void onClick(View v)
            {
                MainBodyActivity.getInstance().goto_fafa_instant_delivery_activity();
            }
        });

        develop_test_page_home_fragment_linearlayout.setOnClickListener(new View.OnClickListener()
        {
            @Override
            public void onClick(View v)
            {
                Bundle bundle = new Bundle(); 
                UIHelper_fafa.showSimpleBack(MainTabMyPageExtendActivity.this, SimpleBackPage_fafa.DEVELOP_TEST_PAGE_HOME_FRAGMENT, bundle);
            }
        });

        baidumapzoomiconchangeactivity_linearlayout.setOnClickListener(new View.OnClickListener()
        {
            @Override
            public void onClick(View v)
            {
                Intent intent = new Intent();
                intent.setClass(getApplicationContext(), com.tjian.fafa.user.module.home.baiduMap.BaiduMapZoomIconChangeActivity.class);
                startActivity(intent);
            }
        });
        mapcontroldemo_fafa_linearlayout.setOnClickListener(new View.OnClickListener()
        {
            @Override
            public void onClick(View v)
            {
                Intent intent = new Intent();
                intent.setClass(getApplicationContext(), com.tjian.fafa.user.module.baiduMap.MapControlDemo_fafa.class);
                startActivity(intent);
            }
        });

    }

    /**
     * 通过URL返回网络的BitMap图片
     *
     * @param urlString
     * @return Bitmap
     */
    public static Bitmap getBitMapForStringURLOld(String urlString)
    {

        URL url = null;
        Bitmap bitmap = null;

        try
        {
            url = new URL(urlString);

            HttpURLConnection conn = (HttpURLConnection) url.openConnection();

            conn.setDoInput(true);
            conn.connect();

            InputStream is = conn.getInputStream();
            bitmap = BitmapFactory.decodeStream(is);

            is.close();

        }
        catch (IOException e)
        {
            e.printStackTrace();
        }
        return bitmap;
    }

    //吕飞
    public void haorenTestButtonOnClick(View view)
    {
        MainBodyActivity.getInstance().gotoRadarDemo();
    }
}
